<!DOCTYPE html>
<html lang="en">
<#include "../common/scripts.html">
<#include "../common/scripts_add.html">
<body >
<div class="page-content" style="min-height:500px;">
    <form action="" method="post" id="editForm" class="form-horizontal">
        <div class="fh-subtitle">用户信息</div>
        <table class="table-main" style="width: 80% !important; border-collapse:collapse;">
            <tr>
                <td style="width: 10%;"><span>所属公司</span></td>
                <td>
                    <div class="input-group" style="width: 100%;">
                        <input type="text" class="form-control" id="companyName" name="companyName"  value="${user.companyName!}"style="border: 0; " readonly />
                    </div>
                </td>
                <td style="width: 10%;"><span>用户名</span></td>
                <td style="position: relative;">
                    <input  class="form-control-gx" value="${user.username!}" name="username" id="username" readonly/>
                </td>
            </tr>
            <tr>
                <td><span>工号</span></td>
                <td><input type="text" class="form-control-gx"  value="${user.userCode!}" name="userCode" id="userCode" readonly></td>
                <td style="width: 10%;"><span>姓名</span></td>
                <td style="position: relative;">
                    <input  class="form-control-gx" value="${user.name!}" name="name" id="name" readonly/>
                </td>
            </tr>
            <tr>
                <td><span>说明</span></td>
                <td  colspan="3">
                    <input  class="form-control-gx" type="text" name="remark" id = "remark" value="${user.remark!}" style="height: 50px;" readonly>
                </td>
            </tr>
        </table>
    <div class="fh-subtitle">分配角色</div>
    <div class="data-list-2" style="width: 80%!important;padding: 0px;">
        <table id="userRoleTable" class="eamtable">
            <thead>
            <tr style="background: #ECEFF0; color: #777;">
                <th>ID</th>
                <th>角色名称</th>
                <th>角色编码</th>
                <th>应用名称</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <div class="fh-subtitle">分配岗位</div>
    <div class="data-list-2" style="width: 80%!important;padding: 0px;">
        <table id="userPostGroupTable" class="eamtable">
            <thead>
            <tr style="background: #ECEFF0; color: #777;">
                <th>ID</th>
                <th>岗位名称</th>
                <th>岗位编码</th>
            </tr>
            </thead>
            <tbody>
            </tbody>
        </table>
    </div>
    <div class="text-center" style="width: 80%; margin-bottom: 50px;">
        <span class="model-btn" onclick="changeClose()" style="width:80px;">关闭</span>
    </div>
</div>

</form>
<script>
    var userRoleTable = $("#userRoleTable");
    var userPostGroupTable = $("#userPostGroupTable");
    $(function(){
        var id = '${user.id!}';
        var username = '${user.username!}';
        userRoleTable.dataTable({
            aLengthMenu: [10000],
            bLengthChange: false,
            bSort: false,
            columns: [
                {data: "id", title: "ID",visible:false},
                {data: "roleName", title: "角色名称"},
                {data: "roleCode", title: "角色编码"},
                {data: "applicationName", title: "应用名称"},
            ],
            "language": {
                "url": "${static}/plugin/datatable/media/i18n/zh_cn.json"
            },
            searching: false,
            "paging": false,
            fnInitComplete: function (oSettings, json) {
                sys.initMenuPower();
                $.ajax({
                    url : "${ctx}/user/getRoleByUserId",
                    type : "POST",
                    datatype : "json",
                    data : {"userId":"${user.id!}"},
                    success : function(data) {
                        if (data.success) {
                            if (isEmpty(data.data)) {
                                rows = [];
                            }
                            var datas = userRoleTable.DataTable().data();
                            var map = iUtils.toKMap(datas, "id");
                            for (var i = 0; i < data.data.length; i++) {
                                if (map[data.data[i].id]) {
                                    data.data.splice(i, 1);
                                    i--;
                                }
                            }
                            userRoleTable.DataTable().rows.add(data.data).draw();
                        } else {
                            sys.topmsg(data.message);
                        }
                    },
                    error : function(data) {
                        js.showMessage("请求异常！","","error",1500)
                    }
                });
            },
            "sDom": '<"row"<"col-sm-12"t><"clear">><"row"<"col-sm-3"l><"col-sm-3"i><"col-sm-6"p><"clear">>',//改变搜索框的位置
        });


        //分配岗位
        userPostGroupTable.dataTable({
            aLengthMenu: [10000],
            bLengthChange: false,
            bSort: false,
            columns: [
                {data: "id", title: "ID",visible:false},
                {data: "postName", title: "岗位名称"},
                {data: "postCode", title: "岗位编码"},
            ],
            "language": {
                "url": "${static}/plugin/datatable/media/i18n/zh_cn.json"
            },
            searching: false,
            "paging": false,
            fnInitComplete: function (oSettings, json) {
                //console.log( 'DataTables 初始化完毕' );
                sys.initMenuPower();
                $.ajax({
                    url : "${ctx}/user/getPostGroupByUserId",
                    type : "POST",
                    datatype : "json",
                    data : {"userId":"${user.id!}"},
                    success : function(data) {
                        if (data.success) {
                            if (isEmpty(data.data)) {
                                rows = [];
                            }
                            var datas = userPostGroupTable.DataTable().data();
                            var map = iUtils.toKMap(datas, "id");
                            for (var i = 0; i < data.data.length; i++) {
                                if (map[data.data[i].id]) {
                                    data.data.splice(i, 1);
                                    i--;
                                }
                            }
                            userPostGroupTable.DataTable().rows.add(data.data).draw();
                        } else {
                            sys.topmsg(data.message);
                        }
                    },
                    error : function(data) {
                        js.showMessage("请求异常！","","error",1500)
                    }
                });
            },
            "sDom": '<"row"<"col-sm-12"t><"clear">><"row"<"col-sm-3"l><"col-sm-3"i><"col-sm-6"p><"clear">>',//改变搜索框的位置
        });

    });
    function changeClose() {
        js.closeCurrentTabPage(function(contentWindow){
            contentWindow.reload();
        });
    }
</script>
</body>
</html>
